<?php
    session_start();
    if(!isset($_SESSION['loggedin'])) header('Location: index.php');

    $pwchanged="none";
    $namechanged="none";
    if(isset($_POST['newpassword']) && isset($_POST['oldpassword'])){
        $pwurl = "http://localhost:8080/TestYourselfASE/rest/user/changePassword/".$_SESSION['userid']."/".$_POST['oldpassword']."/".$_POST['newpassword'];
        $pwfile = file_get_contents($pwurl);
        $pwobj = json_decode($pwfile);
        if(isset($pwobj->Done)) $pwchanged="success";
        else $pwchanged="error";
    }
    if(isset($_POST['newname'])){
        $unurl = "http://localhost:8080/TestYourselfASE/rest/user/changeUsername/".$_SESSION['userid']."/".$_POST['newname'];
        $unfile = file_get_contents($unurl);
        $unobj = json_decode($unfile);
        if(isset($unobj->Done)) $namechanged="success";
        else $namechanged="error";
    }
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="../../assets/ico/favicon.ico">

    <title>TestYourSelf - Login</title>

    <!-- Bootstrap core CSS -->
    <link href="../../bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/profil.css" rel="stylesheet">
    <link href="css/template.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>



<div class="site-wrapper">

    <div class="site-wrapper-inner">

        <div class="cover-container">

            <div class="masthead clearfix">
                <div class="inner">
                    <h3 class="masthead-brand">TestYourSelf</h3>
                    <ul class="nav masthead-nav">
                        <li><a href="select.php">Start</a></li>
                        <li><a href="highscore.php">Highscore</a></li>
                        <li class="active"><a href="#">Profil</a></li>
                        <li><a href="logout.php">Logout</a></li>
                        <?php if(isset($_SESSION['isadmin']) && $_SESSION['isadmin']=="true"){ ?>
                        <li><a href="admin.php">Administration</a></li>
                        <?php } ?>
                    </ul>
                </div>
            </div>

            <div class="inner cover">

                <?php
                    echo '<h1 class="cover-heading">Profil von '.$_SESSION['loggedin'].'</h1>'
                ?>

                <?php if($pwchanged=="error" || $namechanged=="error") echo ' <div class="saveerror">Fehler bei der Speicherung (ggf. Passworteingabe nicht korrekt)!</div>'; ?>
                <?php if($pwchanged=="success" || $namechanged=="success") echo ' <div class="savesuccess">Speicherung war erfolgreich!</div>'; ?>
                <form class="form-signin" role="form" action="profil.php" method="post">
                    <div class="form-heading">M&oumlchten Sie Ihr Passwort &aumlndern?:</div>
                    <input type="password" name="oldpassword" class="form-control" placeholder="Altes Passwort" required>
                    <input type="password" name="newpassword" class="form-control" placeholder="Neues Passwort" required>
                    <button class="btn btn-lg btn-primary btn-block" type="submit">&Aumlndern</button>
                </form>
                <form class="form-signin" role="form" action="profil.php" method="post">
                    <div class="form-heading">M&oumlchten Sie Ihren Benutzernamen &aumlndern?:</div>
                    <input type="text" name="newname" class="form-control" placeholder="Neuer Name" required>
                    <button class="btn btn-lg btn-primary btn-block" type="submit">&Aumlndern</button>
                </form>
            </div>

            <div class="mastfoot">
                <div class="inner">
                    <p>by Christoph Schuster, Martin Schmied, Thomas Stoellner, Philipp Taeubel</p>
                </div>
            </div>

        </div>

    </div>

</div>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="../../bootstrap/js/bootstrap.min.js"></script>
</body>
</html>

